package com.reservationpojo.utils;

import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Map;
import org.springframework.stereotype.Component;
import io.jsonwebtoken.Claims;
import java.util.Date;
public class Jwtutils {
    private static String signkey ="unknown";
    private static Long expire = 43200000L;

    public static String generateJwt(Map<String, Object> claims) {
        Date nowDate = new Date();
        String jwt = Jwts.builder()
                // .setSubject(userId) // 如果需要，取消注释并设置用户ID
                .setIssuedAt(nowDate) // 创建时间
                .addClaims(claims)
                .signWith(SignatureAlgorithm.HS512, signkey)
                .setExpiration(new Date(System.currentTimeMillis() + expire))
                .compact();
        return jwt;
    }

    public static Claims parseJwt(String jwt){
        Claims claims=Jwts.parser()
                .setSigningKey(signkey)
                .parseClaimsJws(jwt)
                .getBody();
        return claims;
    }
}
